﻿<%@ WebHandler Language="C#" Class="ReportTongJiOneTypeHandler" %>

using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using System.IO;
using System.Runtime.Serialization.Json;

public class ReportTongJiOneTypeHandler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        string keywords = "";
        keywords = context.Request.QueryString["keywords"];
        KVModel model;
        List<KVModel> list = new List<KVModel>();


        string str = System.Configuration.ConfigurationManager.ConnectionStrings["decheatConnectionString"].ToString();
        string sql = "exec ReportTongJiOneType " + keywords; 
        SqlConnection conn = new SqlConnection(str);
        conn.Open();
        SqlCommand comm = new SqlCommand(sql, conn);
        System.Data.DataSet ds = new DataSet();
        SqlDataReader dr = comm.ExecuteReader();
        while (dr.Read())
        {

            string typename = dr["typename"].ToString();
            int num = int.Parse(dr["couttimes"].ToString());
            Console.WriteLine(typename + ":" + num);
            model = new KVModel(typename, num);
            list.Add(model);
        }
        //JsonHelper.GetJson<List<Tongji>

        dr.Close();
        if (conn.State == ConnectionState.Open)
        {
            conn.Close();
        }
        //JavaScriptSerializer json = new JavaScriptSerializer();
        string result = WebUI.CommonClass.JSONHelper.Obj2Json<List<KVModel>>(list);
        context.Response.ContentType = "text/plain";
        context.Response.Write(result);
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}